package com.compass.ui.client;

import com.extjs.gxt.charts.client.event.ChartEvent;
import com.extjs.gxt.charts.client.event.ChartListener;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.TreeGridEvent;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.form.HtmlEditor;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout.HBoxLayoutAlign;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Image;

public class PilotPanel extends FlexTable implements Listener<TreeGridEvent<ModelData>>
{
	ContentPanel graph;
	ContentPanel table;
	AdvancedChartExample chart;
	ProjectConfigurationPanel configPanel;
	CommentPanel commentPanel;
	
	public PilotPanel()
	{
		ProjectTree tree = new ProjectTree();
		tree.setHeight("418px");
		tree.setWidth("530px");
		tree.addTreeListener(Events.RowClick, this);
		graph = new ContentPanel();
		table = new ContentPanel();
		table.setHeaderVisible(false);
		table.setSize("1103px", "340px");
		table.setLayout(new FitLayout());
		chart = new AdvancedChartExample(table, "Indicateur");
		HBoxLayout graphLayout = new HBoxLayout();
		graphLayout.setHBoxLayoutAlign(HBoxLayoutAlign.MIDDLE);
		configPanel = new ProjectConfigurationPanel();
		configPanel.addConfigListener(Events.OnClick, new Listener<ComponentEvent>()
				{
					public void handleEvent(ComponentEvent be)
					{
						chart.reload();
					}
					
				});
		commentPanel = new CommentPanel();
		chart.addLineListener(new ChartListener()
			{
				public void chartClick(ChartEvent ce)
				{
					commentPanel.randomExpand();
				}
			});
		chart.setSize("750px", "400px");
		graph.setLayout(graphLayout);
		graph.add(configPanel);
		graph.add(chart);
		graph.add(commentPanel);
		graph.setHeaderVisible(false);
		graph.setHeight("418px");
		graph.setWidth("1103px");
		ContentPanel text = new ContentPanel();
		text.setHeaderVisible(false);
		text.setBorders(false);
		text.setSize("530px", "170px");
		SchedulePanel schedule = new SchedulePanel();
		schedule.setSize("530px", "170px");
		HtmlEditor textArea = new HtmlEditor();
		textArea.setSize("100%", "100%");
		textArea.setBorders(false);
		text.add(textArea);
		ContentPanel projLabel = new ContentPanel();
		projLabel.setHeaderVisible(false);
		projLabel.addText("Pxxxx");
		projLabel.setSize("45px", "45px");
		IndicBar indicBarProj = new IndicBar(3);
		indicBarProj.setSize("450px", "70px");
		IndicBar indicBarPerso = new IndicBar(6);
		indicBarPerso.setSize("650px", "70px");
		Image logo = new Image("./resources/images/logo.jpg");
		logo.setSize("257px", "70px");
		this.setSize("100%", "100%");
		this.setWidget(0, 0, projLabel);
		this.setWidget(0, 1, indicBarProj);
		this.setWidget(0, 2, indicBarPerso);
		this.setWidget(0, 3, logo);
		this.setWidget(1, 0, tree);
		this.setWidget(1, 1, graph);
		this.setWidget(2, 0, text);
		this.setWidget(2, 1, table);
		this.setWidget(3, 0, schedule);
		this.getFlexCellFormatter().setColSpan(1, 0, 2);
		this.getFlexCellFormatter().setColSpan(2, 0, 2);
		this.getFlexCellFormatter().setColSpan(3, 0, 2);
		this.getFlexCellFormatter().setColSpan(1, 1, 2);
		this.getFlexCellFormatter().setColSpan(2, 1, 2);
		this.getFlexCellFormatter().setRowSpan(2, 1, 2);
	}

	@Override
	public void handleEvent(TreeGridEvent<ModelData> be)
	{
		chart.reload();
	}
}
